package cn.jiyun.kafka.consumer;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * 监听类
 */
@Component
public class HelloListener {

    @KafkaListener(topics = "kafka-hello-2111A")
    public void reviceMsg(ConsumerRecord<String,String> record){
        //判断是否有消息内容
        Optional<ConsumerRecord<String, String>> optional = Optional.ofNullable(record);
        //如果有消息内容，接收消息
        if(optional.isPresent()){
            //获取消息内容
            String value = record.value();
            System.out.println(value);
        }
    }

}
